package com.zb.controller;

import com.zb.dto.OrderDto;
import com.zb.entity.TbOrderModel;
import com.zb.service.TbOrderService;
import com.zb.util.TokenDecode;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TbOrderController
 * @Description 控制器
 * @Author zj
 * @Date 2022/11/09 13:57
 **/
@RestController
@RequestMapping("/tb-order-model")
public class TbOrderController {

    @Autowired
    public TbOrderService tbOrderModelService;

    @PostMapping("/add")
    public Integer add(@RequestBody OrderDto orderDto){
        String username= TokenDecode.getUserInfo().get("username");
        TbOrderModel tbOrderModel = new TbOrderModel();
        BeanUtils.copyProperties(orderDto,tbOrderModel);
        tbOrderModel.setUsername(username);
        return tbOrderModelService.addOrder(tbOrderModel,orderDto.getSkuIds());
    }
}